package com.cn.ZhiKeDianShang.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.FrameLayout;

import com.cn.ZhiKeDianShang.MainActivity;
import com.cn.ZhiKeDianShang.R;
import com.cn.ZhiKeDianShang.base.BaseActivity;
import com.cn.ZhiKeDianShang.model.response.UserInfoBean;
import com.cn.ZhiKeDianShang.presenter.LoginUserPresenter;
import com.cn.ZhiKeDianShang.presenter.view.LoginUserView;
import com.cn.ZhiKeDianShang.util.PrefShare;
import com.jph.takephoto.app.TakePhoto;
import com.jph.takephoto.model.InvokeParam;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/7/3.
 * do what to 2017/7/3
 */

public class WelcomeActivity extends BaseActivity<LoginUserView, LoginUserPresenter> implements LoginUserView {

    @BindView(R.id.fl)
    FrameLayout fl;

    //  图片库里面需要的
    private TakePhoto takePhoto;
    private InvokeParam invokeParam;

    @Override
    protected int getNormalLayoutId() {
        return R.layout.activity_welcome;
    }

    @Override
    protected int getErrorLayoutId() {
        return R.layout.activity_welcome;
    }

    @Override
    protected LoginUserPresenter createPresenter() {
        return new LoginUserPresenter(this, this);
    }

    @Override
    protected void initViewsAndEvents() {
        Log.d("Debug", "initViewsAndEvents中--------------");
        //不允许左滑返回
        mSwipeBackLayout.setEnableGesture(false);
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                String token = PrefShare.getInstance(WelcomeActivity.this).getString("token");
                Log.d("Debug", "返回的token只为" + token);
                if (TextUtils.isEmpty(token)) {
                    startActivity(new Intent(WelcomeActivity.this, LoginActivity.class));
                } else {
                    Log.d("Debug", "跳转到列表界面");
                    startActivity(new Intent(WelcomeActivity.this, MainActivity.class));
                }
                finish();
            }
        }, 2000);
////
        fl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
            }
        });
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
        Log.d("Debug","到达onCreate-------------");
        //这个是做  点击Home键到后台 在点击icon 不重启app 而是直接到 之前点击home键的界面
        if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) {
            finish();
            return;
        }
        // 如果不是任务栈第一个页面，就直接结束，显示上一个页面，
        // 主要是部分设备上Jitsi_pre页面退后台再回来会打开这个启动页flg=0x10200000，此时应该结束启动页，回到Jitsi_pre,
        if (!isTaskRoot()) {
            finish();
            return;
        }

    }

    @Override
    public void onLogin(UserInfoBean resultBean) {

    }

    @Override
    public void requestFailed(String message) {

    }


    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        Log.d("Debug", "到达回调这里");
        super.onActivityResult(requestCode, resultCode, data);
    }


}
